
package ui.activity.poscontrol.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import ui.activity.poscontrol.HasPushPosAct;
import ui.activity.poscontrol.beanmodel.PushPeopleBean;


/**
 * POS查询列表适配器
 * Created by chenjian on 19/2/27
 */
public class HasPushPeopleAdapter extends DelegateAdapter.Adapter<HasPushPeopleAdapter.ProfitVH> {

    private final Context mContext;
    private List<PushPeopleBean> datas = new ArrayList<>();

    public HasPushPeopleAdapter(Context context,List<PushPeopleBean> data) {
        mContext = context;
        datas = data;
    }

    public void setData(List<PushPeopleBean> data) {
        datas = data;
        notifyDataSetChanged();
    }


    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public ProfitVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProfitVH(LayoutInflater.from(mContext).inflate(R.layout.layout_haspush_flowedpeople, viewGroup, false));
    }


    @Override
    public void onBindViewHolder(@NonNull ProfitVH holder, int position) {
        if (position < 0 || position >= datas.size()) {
            return;
        }
        String name = datas.get(position).getRealName();
        holder.custom.setText(name);
        holder.posnum.setText(datas.get(position).getCount()+"台");

        holder.flow_custom_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(null == datas.get(position).getPosRecords()||datas.get(position).getPosRecords().size()<1){
                    Intent intent = new Intent(mContext, HasPushPosAct.class);
                    intent.putExtra("toid",datas.get(position).getToId());
                    intent.putExtra("count",datas.get(position).getCount());
                    intent.putExtra("name",datas.get(position).getRealName());
                    mContext.startActivity(intent);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ProfitVH extends RecyclerView.ViewHolder {
        TextView custom;
        ImageView customArrow;
        RelativeLayout flow_custom_head;
        TextView posnum;

        ProfitVH(@NonNull View itemView) {
            super(itemView);
            posnum = itemView.findViewById(R.id.peoplehasposnum);
            custom = itemView.findViewById(R.id.flow_custom_name);
            customArrow = itemView.findViewById(R.id.flow_expand_arrow);
            flow_custom_head = itemView.findViewById(R.id.flow_custom_head);

        }
    }
}
